<template>
  <div>
    <tb-report
      :schemas="schemas"
      :columns="columns"
      :apiUrl="apiUrl"
      :getData="getData"
      :tableData="tableData"
    ></tb-report>
  </div>
</template>

<script>
import TbReport from "@/components/tb-report/index.vue";
import axios from "axios";
import { getQueryString } from "util/index.js";

export default {
  name: "App",
  components: { TbReport },
  data() {
    return {
      title: "首页",
      apiUrl: "/scm/api/v1/scmDemand/list",
      searchParams: {},
      urgencyDegreeOptions: [],
      schemas: [
        {
          label: "追溯号",
          field: "traceBackNo",
          component: "Input",
          placeholder: "追溯号",
          required: false,
          colProps: {},
        },
        {
          label: "紧急程度",
          field: "urgencyDegree",
          component: "Select",
          placeholder: "紧急程度",
          required: false,
          componentProps: ({ form }) => {
            return {
              options: this.urgencyDegreeOptions,
            };
          },
          colProps: {},
        },
        {
          label: "发运计划状态",
          field: "dispatchStatus",
          component: "Checkbox",
          placeholder: "多选",
          required: false,
          componentProps: {
            options: [
              { text: "未提交", value: "1" },
              { text: "已提交", value: "2" },
              { text: "已确认", value: "3" },
              { text: "已退回", value: "4" },
              { text: "已作废", value: "5" },
            ],
          },
          colProps: {},
        },
      ],
      columns: [
        {
          title: "序号",
          fixed: "left",
          type: "seq",
          width: 60,
          align: "center",
        },
        {
          title: "状态",
          key: "demandStatusLabel",
          field: "demandStatusLabel",
          width: 100,
          align: "center",
        },
        {
          title: "追溯号",
          key: "traceBackNo",
          field: "traceBackNo",
          width: 100,
          align: "center",
        },
        {
          title: "物料编码",
          key: "goodsCode",
          field: "goodsCode",
          width: 100,
          align: "center",
        },
        {
          title: "紧急程度",
          key: "urgencyDegreeLabel",
          field: "urgencyDegreeLabel",
          width: 100,
          align: "center",
        },
        {
          title: "项目编号",
          key: "programNumber",
          field: "programNumber",
          width: 100,
          align: "center",
        },
        {
          title: "项目名称",
          key: "programName",
          field: "programName",
          width: 100,
          align: "center",
        },
        {
          title: "项目阶段",
          key: "programStageLabel",
          field: "programStageLabel",
          width: 100,
          align: "center",
        },
        {
          title: "项目客户",
          key: "programCustomer",
          field: "programCustomer",
          width: 100,
          align: "center",
        },
        {
          title: "项目采购经理",
          key: "purchaseManager",
          field: "purchaseManager",
          width: 100,
          align: "center",
        },
        {
          title: "申购单号",
          key: "applyBuyNo",
          field: "applyBuyNo",
          width: 100,
          align: "center",
        },
        {
          title: "申购单审批完结日期",
          key: "approvalCompletionDate",
          field: "approvalCompletionDate",
          width: 100,
          align: "center",
        },
        {
          title: "商品名称",
          key: "goodsName",
          field: "goodsName",
          width: 100,
          align: "center",
        },
        {
          title: "规格/型号",
          key: "goodsSpecificationModel",
          field: "goodsSpecificationModel",
          width: 100,
          align: "center",
        },
        {
          title: "采购业务员",
          key: "purchaser",
          field: "purchaser",
          width: 100,
          align: "center",
        },
        {
          title: "申购单号",
          key: "applyBuyNo",
          field: "applyBuyNo",
          width: 100,
          align: "center",
        },
        {
          title: "用途",
          key: "purpose",
          field: "purpose",
          width: 100,
          align: "center",
        },
        {
          title: "设备位号",
          key: "equipmentItemNo",
          field: "equipmentItemNo",
          width: 100,
          align: "center",
        },
        {
          title: "子项号/成本中心代码",
          key: "childItemNo",
          field: "childItemNo",
          width: 100,
          align: "center",
        },
        {
          title: "申购人",
          key: "applyBuyPerson",
          field: "applyBuyPerson",
          width: 100,
          align: "center",
        },
        {
          title: "需求数量",
          key: "applyBuyQuantity",
          field: "applyBuyQuantity",
          width: 100,
          align: "center",
        },
        {
          title: "已购数量",
          key: "alreadyPurchaseQuantity",
          field: "alreadyPurchaseQuantity",
          width: 100,
          align: "center",
        },
        {
          title: "成交单位",
          key: "tradeUnitLabel",
          field: "tradeUnitLabel",
          width: 100,
          align: "center",
        },
        {
          title: "交货周期/天",
          key: "deliveryCycle",
          field: "deliveryCycle",
          width: 100,
          align: "center",
        },
        {
          title: "需求接单日期",
          key: "demandAcceptDate",
          field: "demandAcceptDate",
          width: 100,
          align: "center",
        },
        {
          title: "需求派单日期",
          key: "demandAllotDate",
          field: "demandAllotDate",
          width: 100,
          align: "center",
        },
        {
          title: "要求合同签订日期",
          key: "requireSignedDate",
          field: "requireSignedDate",
          width: 100,
          align: "center",
        },
        {
          title: "预计合同签订日期",
          key: "planSignedDate",
          field: "planSignedDate",
          width: 100,
          align: "center",
        },
      ],
      tableData: [],
    };
  },
  methods: {
    getAllOptions() {
      let _this = this;

      axios({
        method: "get",
        headers: {
          Authorization: "Bearer " + getQueryString("token"),
        },
        params: {},
        url: "/scm/api/v1//scmBasicDataDictionary/listByTypeCode/urgency_Degree",
      }).then((response) => {
        console.log("response", response.data.data);
        if (response.data.code === 0) {
          _this.urgencyDegreeOptions = response.data.data.map((item) => {
            return {
              text: item.paramName,
              value: item.paramCode,
            };
          });
        }
      });
    },
    getData(data) {
      if (this.tableData.length == 0) {
        this.tableData = data;
      } else {
        this.tableData = [...this.tableData, ...data];
      }
    },
  },
  mounted() {
    this.getAllOptions();
  },
};
</script>

<style>
</style>
